﻿#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <map>

#include "RBTree.h"
#include "my_set.h"
#include "my_map.h"
void test()
{
	srand((unsigned int)time(nullptr));
	zzb::set<int> s;
	/*s.insert(1);
	s.insert(2);
	s.insert(3);
	s.insert(4);
	s.insert(5);
	s.insert(6);*/


	int N = 100;
	for (int i = 0; i < N; ++i)
	{
		s.insert(rand() + i);
	}
	auto it = s.begin();
	while (it != s.end())
	{
		cout << *it << ' ';
		++it;
	}
	cout << endl;
}
void test1()
{
	srand((unsigned int)time(nullptr));
	zzb::map<string, int> m;
	/*m.insert(make_pair("string", "字符串"));
	m.insert(make_pair("dict", "字典"));
	m.insert(make_pair("left", "左边"));*/
	zzb::map<string, string> intm;
	

	string nums[] = { "苹果", "香蕉", "西瓜", "苹果", "香蕉", "西瓜", "苹果" , "西瓜", "苹果" };

	for (auto& e : nums)
	{
		m[e]++;
	}
	//zzb::map<string, int> t1(m);
	zzb::map<string, int> t1;
	t1 = m;

	auto it = m.begin();
	while (it != m.end())
	{
		cout << it->first << ' ' << it->second << ' ';
		++it;
	}
	cout << endl;

	it = t1.begin();
	while (it != t1.end())
	{
		cout << it->first << ' ' << it->second << ' ';
		++it;
	}
	cout << endl;
}
void CheckWord(zzb::map<int, string>& dict, const string& word)
{
	dict[1];
	//找完全匹配的
	for (int i = 0; i < dict.size(); ++i)
	{
		if (dict[i] == word)
		{
			cout << word << " is correct" << endl;
			//找到了直接返回
			return;
		}
	}
	cout << word << ":";
	//没找到匹配的,找建议修改的单词
	for (int i = 0; i < dict.size(); ++i)
	{
		int different = 0;
		if (dict[i].size() == word.size())
		{
			//长度相同,统计不一样的字符个数
			for (int j = 0; j < word.size(); ++j)
			{
				if (dict[i][j] != word[j])
				{
					different++;
				}
			}
			//只有一个字符不同，该单词为建议修改单词，输出
			if (different == 1)
			{
				cout << " " << dict[i];
			}
		}
		else if (dict[i].size() + 1 == word.size())
		{
			//长度不同,比待检测单词长短1
			// 统计不一样的字符个数
			int j = 0, k = 0;
			while (j < dict[i].size() && k < word.size())
			{
				if (dict[i][j] != word[k])
				{
					different++;
					k++;
				}
				else
				{
					j++;
					k++;
				}
				if (different > 1)
				{
					break;
				}
			}
			while (j < dict[i].size())
			{
				different++;
				j++;
			}
			while (k < word.size())
			{
				different++;
				k++;
			}
			//只有一个字符不同，该单词为建议修改单词，输出
			if (different == 1)
			{
				cout << " " << dict[i];
			}
		}
		else if (dict[i].size() == word.size() + 1)
		{
			//长度不同,比待检测单词长短1
			// 统计不一样的字符个数
			int j = 0, k = 0;
			while (j < dict[i].size() && k < word.size())
			{
				if (dict[i][j] != word[k])
				{
					different++;
					j++;
				}
				else
				{
					j++;
					k++;
				}
				if (different > 1)
				{
					break;
				}
			}
			while (j < dict[i].size())
			{
				different++;
				j++;
			}
			while (k < word.size())
			{
				different++;
				k++;
			}
			//只有一个字符不同，该单词为建议修改单词，输出
			if (different == 1)
			{
				cout << " " << dict[i];
			}
		}
	}
	cout << endl;
}


int main()
{
	test1();
	//zzb::map<int, string> dict;//vector充当顺序表
	////读取字典中的单词
	//string word;
	//int i = 0;
	//while (cin >> word && word != "#")
	//{
	//	dict[i++] = word;
	//}
	//dict.PostOrder();
	////依次检测所有待检测的单词
	//while (cin >> word && word != "#")
	//{
	//	CheckWord(dict, word);
	//}
}

//int main()
//{
//	test2();
//	/*RBTree<int, int> rbTree;
//	int nums[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
//	for (auto e : nums)
//	{
//		rbTree.insert(make_pair(e, e));
//	}
//	rbTree.InOrder();
//	cout << rbTree.IsRbTree() << endl;*/
//	return 0;
//}

























//int main()
//{
//
//	const int N = 1000;
//	srand((unsigned int)time(nullptr));
//	RBTree<int, int> rbTree;
//	//int nums[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
//	//int nums[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
//	for (int i = 0; i < N; ++i)
//	{
//		int num = rand() + i;
//		rbTree.insert(make_pair(num, num));
//	}
//	//rbTree.InOrder();
//	cout << rbTree.IsRbTree();
//	return 0;
//}